package cn.xyfmzmy.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * 省
 */
public class Province implements PopulationNode{

    private String name;

    // 一个省里有多个市
    private List<City> cityList = new ArrayList<>();

    public Province(String name) {
        this.name = name;
    }

    public void add(City city){
        this.cityList.add(city);
    }

    @Override
    public int computePopulation() {
        return cityList.stream().mapToInt(City::computePopulation).sum();
    }
}
